﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.EnumMemberDecl"/>.
    /// </summary>
    public class EnumMemberDeclVM : VariableDeclVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(EnumMemberDecl),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new EnumMemberDeclVM((EnumMemberDecl)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.EnumMemberDecl"/>.
        /// </summary>
        public EnumMemberDeclVM(EnumMemberDecl enumMemberDecl, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(enumMemberDecl, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.EnumMemberDecl"/> model.
        /// </summary>
        public EnumMemberDecl EnumMemberDecl
        {
            get { return (EnumMemberDecl)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        protected override void RenderStatement(CodeRenderer renderer, RenderFlags flags)
        {
            RenderFlags passFlags = (flags & RenderFlags.PassMask);
            bool isDescription = flags.HasFlag(RenderFlags.Description);

            if (isDescription)
            {
                EnumDecl parentEnumDecl = EnumMemberDecl.ParentEnumDecl;
                if (parentEnumDecl != null)
                {
                    ((EnumDeclVM)CreateVM(parentEnumDecl)).RenderName(renderer, flags);
                    DotVM.RenderDot(renderer, this);
                }
            }
            renderer.RenderText(EnumMemberDecl.Name, IDENTIFIER_BRUSH, this);

            if (EnumMemberDecl.Initialization != null)
                RenderInitialization(renderer, passFlags);
        }

        #endregion
    }
}
